import re

line = "cats are so beautiful"
pattern = r'(.*) are (.*?) .*'

#match 从头开始匹配！
res = re.match(pattern, line)
print(res.groups())
print(res.group(1))
print(res.group(0))


#search 扫描整个字符串，有匹配到的就成功
pattern2 = r'so'
res1 = re.match(pattern2, line)
res2 = re.search(pattern2, line)
print(res1)
print(res2.span())


#sub 替换匹配到的内容
phone = '1001-1111-2222 #123456'
num = re.sub(r'#.*$' ,'',phone)
print(num)

num = re.sub(r'\D','',num)
print(num)

obj = re.compile(r'\d+')
result1 = obj.findall('obj 123 jasad 92837821')
print(result1)

